<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:replace="admin/head :: head"></div>
    <title>用户表单</title>
</head>

<body>
<div class="x-body layui-anim layui-anim-up">
    <form class="layui-form">
        <input type="hidden" name="id" th:value="${user eq null ? '' : user.id}"/>
        <input type="hidden" name="filtrate" th:value="${user eq null ? '' : user.filtrate}"/>

        <div class="layui-form-item">
            <label for="L_account" class="layui-form-label">
                账号
            </label>
            <div class="layui-input-inline width-30">
                <input type="text" id="L_account" name="account" required="" lay-verify="account" autocomplete="off"
                       class="layui-input" th:value="${user eq null ? '' : user.account}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_pwd" class="layui-form-label">
                密码
            </label>
            <div class="layui-input-inline width-30">
                <input type="text" id="L_pwd" name="pwd" required="" lay-verify="pwd" autocomplete="off"
                       class="layui-input" value="" placeholder="密码为6-20个字符, 可包含字母、数字、下划线, 为空则不修改">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_name" class="layui-form-label">
                姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_name" name="name" required="" lay-verify="name" autocomplete="off"
                       class="layui-input" th:value="${user eq null ? '' : user.name}">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_nickname" class="layui-form-label">
                昵称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_nickname" name="nickname" required="" lay-verify="nickname" autocomplete="off"
                       class="layui-input" th:value="${user eq null ? '' : user.nickname}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_description" class="layui-form-label">
                介绍
            </label>
            <div class="layui-input-inline width-50">
                <textarea placeholder="请输入介绍内容" id="L_description" name="description" required=""
                          lay-verify="description"
                          class="text-area">[[${user eq null ? '' : user.description}]]</textarea>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_type" class="layui-form-label">
                用户类型
            </label>
            <div class="layui-input-inline">
                <select name="type" class="layui-input" id="L_type">
                    <option th:each="item, index:${roles}" th:value="${item.id}" th:text="${item.description}"
                            th:selected="${user ne null and user.type ne null and user.type eq item.id}"></option>

                    <!--<option th:selected="${user ne null and user.type eq 0}" value="0">用户</option>
                    <option th:selected="${user ne null and user.type eq 1}" value="1">摄影师</option>
                    <option th:selected="${user ne null and user.type eq 2}" value="2">编剧</option>
                    <option th:selected="${user ne null and user.type eq 98}" value="98">后台编辑</option>
                    <option th:selected="${user ne null and user.type eq 99}" value="99">管理员</option>-->
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_gender" class="layui-form-label">
                性别
            </label>
            <div class="layui-input-inline">
                <select name="gender" class="layui-input" id="L_gender">
                    <option th:selected="${user ne null and user.gender eq 0}" value="0">女</option>
                    <option th:selected="${user ne null and user.gender eq 1}" value="1">男</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_mobile" class="layui-form-label">
                电话
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_mobile" name="mobile" autocomplete="off"
                       class="layui-input" th:value="${user eq null ? '' : user.mobile}">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_email" class="layui-form-label">
                邮箱
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_email" name="email" autocomplete="off"
                       class="layui-input" th:value="${user eq null ? '' : user.email}">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_address_0" class="layui-form-label">
                地址
            </label>
            <input type="hidden" name="address" id="L_address" lay-verify="address"
                   th:value="${user ne null and user.address ne null ? user.address : ''}">
            <div class="layui-input-inline">
                <select class="layui-input" id="L_address_0" lay-filter="address-selector-parent">
                    <option value="">请选择</option>
                    <option th:each="item, index:${areas}" th:if="${item.pid eq 0}" th:value="${item.id}"
                            th:text="${item.name}"></option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select class="layui-input" id="L_address_1" lay-filter="address-selector-second">

                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_graduateInstitution" class="layui-form-label">
                毕业院校
            </label>
            <div class="layui-input-inline width-50">
                <textarea class="text-area" placeholder="请输入内容" id="L_graduateInstitution" name="graduateInstitution"
                          required="" lay-verify="graduateInstitution" autocomplete="off">[[${user ne null and user.graduateInstitution ne null ? user.graduateInstitution : ''}]]</textarea>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_mainAchievements" class="layui-form-label">
                主要成就
            </label>
            <div class="layui-input-inline width-50">
                <textarea class="text-area" placeholder="请输入内容" id="L_mainAchievements" name="mainAchievements"
                          required="" lay-verify="mainAchievements" autocomplete="off">[[${user ne null and user.mainAchievements ne null ? user.mainAchievements : ''}]]</textarea>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_personalizedSignature" class="layui-form-label">
                一句话
            </label>
            <div class="layui-input-inline width-50">
                <textarea class="text-area" placeholder="请输入内容" id="L_personalizedSignature"
                          name="personalizedSignature" required="" lay-verify="personalizedSignature"
                          autocomplete="off">[[${user ne null and user.personalizedSignature ne null ? user.personalizedSignature : ''}]]</textarea>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_background" class="layui-form-label">
                背景
            </label>
            <div class="layui-input-inline width-50">
                <textarea class="text-area" placeholder="请输入内容" id="L_background" name="background" required=""
                          lay-verify="background" autocomplete="off">[[${user ne null and user.background ne null ? user.background : ''}]]</textarea>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_roles" class="layui-form-label">
                权限
            </label>
            <div class="layui-input-inline" id="L_roles">
                <input type="checkbox"
                       th:each="item, index:${roles}"
                       th:name="'roles[' + ${index.index} + '].id'"
                       th:checked="${(user ne null and user.roles ne null and user.roles.contains(item)) ? true : false}"
                       th:value="${item.id}" th:title="${item.description}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_order" class="layui-form-label">
                排序(从高到低)
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_order" name="order" autocomplete="off"
                       class="layui-input" th:value="${user eq null ? '' : user.order}">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_status" class="layui-form-label">
                状态
            </label>
            <div class="layui-input-inline">
                <select name="status" class="layui-input" id="L_status" lay-verify="required">
                    <option th:selected="${user ne null and user.status eq 0}" value="0">不可用</option>
                    <option th:selected="${user ne null and user.status eq 1}" value="1">可用</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>


        <input value="1" id="portrait_width" type="hidden">
        <input value="1" id="portrait_height" type="hidden">
        <input value="82" id="portrait_top" type="hidden">
        <input value="73" id="portrait_left" type="hidden">
        <input value="120" id="portrait_DropWidth" type="hidden">
        <input value="120" id="portrait_DropHeight" type="hidden">
        <div class="layui-form-item">
            <label for="L_portrait" class="layui-form-label">
                头像
            </label>
            <div class="layui-input-inline width-600">
                <input type="hidden" name="portrait" id="L_portrait" th:value="${user ne null ? user.portrait : ''}"
                       required="" lay-verify="img" autocomplete="off" class="">
                <input type="hidden" id="L_old_portrait" th:value="${user ne null ? user.portrait : ''}"
                       autocomplete="off" class="">
                <div class="jcrop-div">
                    <div class="pic-btn">
                        <button type="button" class="invisible" id="L_portrait_upload" value="选择图片"></button>
                        <span class="x-red">*</span>
                    </div>
                    <div class="pic-img">
                        <img class="pictureWrap" th:if="${user ne null and user.portrait ne null}"
                             th:src="${#request.getAttribute('uploadServer')} + ${user.portrait}"
                             id="L_portrait_pic" style="height: 300px; width: 300px; display: block;"/>
                        <img class="pictureWrap" th:if="${user eq null or user.portrait eq null}"
                             th:src="${#request.getAttribute('ctx') + '/static/front/img/default_portrait.png'}"
                             id="L_portrait_pic" style="height: 300px; width: 300px; display: block;"/>
                    </div>
                    <div id="L_portrait_preview_pane" class="preview-pane1">
                        <div class="preview-container w180h180">
                            <img id="L_portrait_jcrop_preview"
                                 th:src="${#request.getAttribute('ctx') + '/static/front/img/default_portrait.png'}"
                                 class="jcrop-preview"/>
                        </div>
                    </div>
                </div>
            </div>
            <button id="L_portrait_jcrop_destroy" type="button"></button>
        </div>


        <!--<input value="1" id="photo_width" type="hidden">
        <input value="1" id="photo_height" type="hidden">
        <input value="82" id="photo_top" type="hidden">
        <input value="73" id="photo_left" type="hidden">
        <input value="120" id="photo_DropWidth" type="hidden">
        <input value="120" id="photo_DropHeight" type="hidden">
        <div class="layui-form-item">
            <label for="L_photo" class="layui-form-label">
                PC展示照片
            </label>
            <div class="layui-input-inline width-600">
                <input type="hidden" name="photo" id="L_photo" th:value="${user ne null ? user.photo : ''}" required=""
                       lay-verify="img" autocomplete="off" class="">
                <input type="hidden" id="L_old_photo" th:value="${user ne null ? user.photo : ''}" autocomplete="off"
                       class="">
                <div class="jcrop-div">
                    <div class="pic-btn">
                        <button type="button" class="invisible" id="L_photo_upload" value="选择图片"></button>
                        <span class="x-red">*</span>
                    </div>
                    <div class="pic-img">
                        <img class="pictureWrap" th:if="${user ne null and user.photo ne null}"
                             th:src="${#request.getAttribute('uploadServer')} + ${user.photo}"
                             id="L_photo_pic" style="height: 211px; width: 150px; display: block;"/>
                        <img class="pictureWrap" th:if="${user eq null or user.photo eq null}"
                             th:src="${#request.getAttribute('ctx') + '/static/front/img/default_portrait.png'}"
                             id="L_photo_pic" style="height: 211px; width: 150px; display: block;"/>
                    </div>
                    <div id="L_photo_preview_pane" class="preview-pane1">
                        <div class="preview-container w150h211">
                            <img id="L_photo_jcrop_preview"
                                 th:src="${#request.getAttribute('ctx') + '/static/front/img/default_portrait.png'}"
                                 class="jcrop-preview"/>
                        </div>
                    </div>
                </div>
            </div>
            <button id="L_photo_jcrop_destroy" type="button"></button>
        </div>


        <input value="1" id="mobilePhoto_width" type="hidden">
        <input value="1" id="mobilePhoto_height" type="hidden">
        <input value="82" id="mobilePhoto_top" type="hidden">
        <input value="73" id="mobilePhoto_left" type="hidden">
        <input value="120" id="mobilePhoto_DropWidth" type="hidden">
        <input value="120" id="mobilePhoto_DropHeight" type="hidden">
        <div class="layui-form-item">
            <label for="L_mobile_photo" class="layui-form-label">
                移动设备展示照片
            </label>
            <div class="layui-input-inline width-600">
                <input type="hidden" name="mobilePhoto" id="L_mobile_photo"
                       th:value="${user ne null ? user.mobilePhoto : ''}" required="" lay-verify="img"
                       autocomplete="off" class="">
                <input type="hidden" id="L_old_mobile_photo" th:value="${user ne null ? user.mobilePhoto : ''}"
                       autocomplete="off" class="">
                <div class="jcrop-div">
                    <div class="pic-btn">
                        <button type="button" class="invisible" id="L_mobile_photo_upload" value="选择图片"></button>
                        <span class="x-red">*</span>
                    </div>
                    <div class="pic-img">
                        <img class="pictureWrap" th:if="${user ne null and user.mobilePhoto ne null}"
                             th:src="${#request.getAttribute('uploadServer')} + ${user.mobilePhoto}"
                             id="L_mobile_photo_pic" style="height: 135px; width: 183px; display: block;"/>
                        <img class="pictureWrap" th:if="${user eq null or user.mobilePhoto eq null}"
                             th:src="${#request.getAttribute('ctx') + '/static/front/img/default_portrait.png'}"
                             id="L_mobile_photo_pic" style="height: 135px; width: 183px; display: block;"/>
                    </div>
                    <div id="L_mobile_photo_preview_pane" class="preview-pane1">
                        <div class="preview-container w183h135">
                            <img id="L_mobile_photo_jcrop_preview"
                                 th:src="${#request.getAttribute('ctx') + '/static/front/img/default_portrait.png'}"
                                 class="jcrop-preview"/>
                        </div>
                    </div>
                </div>
            </div>
            <button id="L_mobile_photo_jcrop_destroy" type="button"></button>
        </div>-->

        <!--<div class="layui-form-item">
            <label for="L_photo" class="layui-form-label">
                PC展示照片
            </label>
            <div class="layui-upload">
                <div class="layui-input-block ">
                    <input class="layui-input" type="hidden" name="photo" id="L_photo" th:value="${user eq null ? '' : user.photo}" required="" lay-verify="img" autocomplete="off" >
                    <img th:if="${user ne null and user.photo ne null}" th:src="${#request.getAttribute('uploadServer')} + ${user.photo}" id="L_photo_pic"  width="210px" height="300px" />
                    <img th:if="${user eq null or user.photo eq null}" th:src="${#request.getAttribute('ctx') + '/static/front/img/default_head.jpg'}" id="L_photo_pic"  width="210px" height="300px" />
                    <input type="button" value="上传图片" id="upload2"/> (支持jpg, png - 210px × 300px)<span class="x-red">*</span>
                </div>
            </div>
        </div>-->

        <!--<div class="layui-form-item">
            <label for="L_mobile_photo" class="layui-form-label">
                移动设备展示照片
            </label>
            <div class="layui-upload">
                <div class="layui-input-block ">
                    <input class="layui-input" type="hidden" name="mobilePhoto" id="L_mobile_photo" th:value="${user eq null ? '' : user.mobilePhoto}" required="" lay-verify="img" autocomplete="off" >
                    <img th:if="${user ne null and user.mobilePhoto ne null}" th:src="${#request.getAttribute('uploadServer')} + ${user.mobilePhoto}" id="L_mobile_photo_pic"  width="170px" height="105px" />
                    <img th:if="${user eq null or user.mobilePhoto eq null}" th:src="${#request.getAttribute('ctx') + '/static/front/img/default_head.jpg'}" id="L_mobile_photo_pic"  width="170px" height="105px" />
                    <input type="button" value="上传图片" id="upload3"/> (支持jpg, png - 170px × 105px)<span class="x-red">*</span>
                </div>
            </div>
        </div>-->

        <div class="layui-form-item">
            <button id="submit-btn" class="layui-btn" type="button" lay-filter="add" lay-submit="">
                保存
            </button>
        </div>
    </form>
</div>
<link rel="stylesheet" th:href="${#request.getAttribute('ctx') + '/static/common/kindeditor/themes/default/default.css'}">
<link rel="stylesheet" th:href="${#request.getAttribute('ctx') + '/static/common/Jcrop-0.9.12/jquery.Jcrop.min.css'}">


<script type="text/javascript" th:src="${#request.getAttribute('ctx') + '/static/common/kindeditor/kindeditor-all-min.js'}"></script>
<!-- Jcrop -->
<script type="text/javascript" th:src="${#request.getAttribute('ctx') + '/static/common/Jcrop-0.9.12/jquery.Jcrop.min.js'}"></script>

<script th:inline="javascript">
    var areas = [[${areas}]];
</script>

<script>

    function submitBusy(busy) {
        if (busy) {
            $('#submit-btn').attr('disabled', 'disabled');
        } else {
            $('#submit-btn').removeAttr('disabled');
        }
    }

    // 210 × 300
    /*initSimpleImageUpload('upload2', 'kpoint-cover', function(btnId, imgUrl) {
        $("#L_photo").val(imgUrl);
        $("#L_photo_pic").attr("src", fileServer + imgUrl);
    },'',true,'210','300');*/

    // 170 × 105
    /*initSimpleImageUpload('upload3', 'kpoint-cover', function(btnId, imgUrl) {
        $("#L_mobile_photo").val(imgUrl);
        $("#L_mobile_photo_pic").attr("src", fileServer + imgUrl);
    },'',true,'170','105');*/

    // 头像剪裁
    webImageUpload('L_portrait_upload', 'temp&cutImg=true&scaleType=scale&scale=0.7', calTitleImg,
        '#L_portrait', '#L_portrait_pic', '#L_portrait_preview_pane', '#L_portrait_jcrop_preview', '#L_portrait_jcrop_destroy', 1 / 1);

    // PC预览
    /*webImageUpload('L_photo_upload', 'temp&cutImg=true&scaleType=scale&scale=0.7', calTitleImg,
        '#L_photo', '#L_photo_pic', '#L_photo_preview_pane', '#L_photo_jcrop_preview', '#L_photo_jcrop_destroy', 300 / 422);*/

    // 手机预览
    /*webImageUpload('L_mobile_photo_upload', 'temp&cutImg=true&scaleType=scale&scale=0.7', calTitleImg,
        '#L_mobile_photo', '#L_mobile_photo_pic', '#L_mobile_photo_preview_pane', '#L_mobile_photo_jcrop_preview', '#L_mobile_photo_jcrop_destroy', 183 / 135);*/

    function savePortrait(json) {
        if (json.error != 0) {
            layer.alert(json.message, {icon: 1, time: 3000});
            return;
        }
        $('#L_portrait').val(json.src);
    }

    /*function savePhoto(json) {
        if (json.error != 0) {
            layer.alert(json.message, {icon: 1, time: 3000});
            return;
        }
        $('#L_photo').val(json.src);
    }*/

    /*function saveMobilePhoto(json) {
        if (json.error != 0) {
            layer.alert(json.message, {icon: 1, time: 3000});
            return;
        }
        $('#L_mobile_photo').val(json.src);
    }*/

    var interval, formData, uploadCount = 0;


    function updateUser() {
        if (uploadCount < 1) {
            return;
        }

        clearInterval(interval);

        var roles = $('#L_roles .layui-unselect.layui-form-checkbox.layui-form-checked').length;
        if (roles == 0) {
            layer.alert(Messages.USER.ROLES_CAN_NOT_BE_NULL, {icon: 1, time: 3000});
            submitBusy(false);
            return;
        }

        $.ajax({
            type: 'post',
            url: '/admin/user/save',
            async: false,
            data: formData.field,
            dataType: 'json',
            beforeSend: function (xhr) {
                xhr.setRequestHeader($("meta[name='_csrf_header']").attr("content"), $("meta[name='_csrf']").attr("content"));
            },
            success: function (result) {
                if (result.status == 200) {
                    layer.alert(Messages.SUCCESS, {icon: 6}, function () {
                        // get frame index
                        var index = parent.layer.getFrameIndex(window.name);
                        // refresh parent list and close current dialog
                        parent.location.reload();
                        parent.layer.close(index);
                    });
                } else if (result.status == -2) {
                    var msg = '';
                    for (var i in result.data) {
                        msg += result.data[i] + ';';
                    }
                    layer.alert(result.error == null || result.error == undefined ? Messages.ERROR : msg, {icon: 1});
                    submitBusy(false);
                } else {
                    layer.alert(result.error == null || result.error == undefined ? Messages.ERROR : result.error, {icon: 1});
                    submitBusy(false);
                    return false;
                }
            },
            error: function (e) {
                layer.alert(Messages.ERROR, {icon: 1});
                submitBusy(false);
            }
        })
    }

    /**
     * upload portrait
     */
    function uploadPortrat() {
        var portraitPath = $("#L_portrait").val();
        var portraitOldPath = $('#L_old_portrait').val();
        if (portraitPath == null || portraitPath == '') {
            clearInterval(interval);
            layer.alert('请上传头像', {icon: 1, time: 3000});
            submitBusy(false);
            return;
        } else {
            if (portraitPath != portraitOldPath) {
                var params = "photoPath=" + portraitPath
                    + "&txt_width=" + $("#portrait_width").val()
                    + "&txt_height=" + $("#portrait_height").val()
                    + "&txt_top=" + $("#portrait_top").val()
                    + "&txt_left=" + $("#portrait_left").val()
                    + "&txt_DropWidth=" + $("#portrait_DropWidth").val()
                    + "&txt_DropHeight=" + $("#portrait_DropHeight").val();
                $.ajax({
                    url: uploadServer + "/image/saveface",
                    type: 'get',
                    async: false,
                    data: params,
                    dataType: 'jsonp',//here
                    jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
                    jsonpCallback: "savePortrait",
                    success: function (json) {
                        formData.field.portrait = json.src;
                        uploadCount++;
                    },
                    error: function (e) {
                        clearInterval(interval);
                        layer.alert('图片上传失败,请上传宽高均小于900像素,小于200kb的图片', {icon: 1, time: 3000});
                        submitBusy(false);
                        return;
                    }
                });
            } else {
                uploadCount++;
            }
        }
    }

    /**
     * upload photo
     */
    /*function uploadPhoto() {
        var photoPath = $('#L_photo').val();
        var photoOldPath = $('#L_old_photo').val();
        if (photoPath == null || photoPath == '') {
            clearInterval(interval);
            layer.alert('请上传PC端展示图', {icon: 1, time: 3000});
            return;
        } else {
            if (photoPath != photoOldPath) {
                var params = "photoPath=" + photoPath
                    + "&txt_width=" + $("#photo_width").val()
                    + "&txt_height=" + $("#photo_height").val()
                    + "&txt_top=" + $("#photo_top").val()
                    + "&txt_left=" + $("#photo_left").val()
                    + "&txt_DropWidth=" + $("#photo_DropWidth").val()
                    + "&txt_DropHeight=" + $("#photo_DropHeight").val();
                $.ajax({
                    url: uploadServer + "/image/saveface",
                    type: 'get',
                    async: false,
                    data: params,
                    dataType: 'jsonp',//here
                    jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
                    jsonpCallback: "savePhoto",
                    success: function (json) {
                        formData.field.photo = json.src;
                        uploadCount++;
                    },
                    error: function (e) {
                        clearInterval(interval);
                        layer.alert('图片上传失败,请上传宽高均小于900像素,小于200kb的图片', {icon: 1, time: 3000});
                        return;
                    }
                });
            } else {
                uploadCount++;
            }
        }
    }*/

    /**
     * upload mobile photo
     */
    /*function uploadMobilePhoto() {
        var mobilePhotoPath = $("#L_mobile_photo").val();
        var mobilePhotoOldPath = $('#L_old_mobile_photo').val();
        if (mobilePhotoPath == null || mobilePhotoPath == '') {
            clearInterval(interval);
            layer.alert('请上传手机展示图', {icon: 1, time: 3000});
            return;
        } else {
            if (mobilePhotoPath != mobilePhotoOldPath) {
                var params = "photoPath=" + mobilePhotoPath
                    + "&txt_width=" + $("#mobilePhoto_width").val()
                    + "&txt_height=" + $("#mobilePhoto_height").val()
                    + "&txt_top=" + $("#mobilePhoto_top").val()
                    + "&txt_left=" + $("#mobilePhoto_left").val()
                    + "&txt_DropWidth=" + $("#mobilePhoto_DropWidth").val()
                    + "&txt_DropHeight=" + $("#mobilePhoto_DropHeight").val();
                $.ajax({
                    url: uploadServer + "/image/saveface",
                    type: 'get',
                    async: false,
                    data: params,
                    dataType: 'jsonp',//here
                    jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
                    jsonpCallback: "saveMobilePhoto",
                    success: function (json) {
                        formData.field.mobilePhoto = json.src;
                        uploadCount++;
                    },
                    error: function (e) {
                        clearInterval(interval);
                        layer.alert('图片上传失败,请上传宽高均小于900像素,小于200kb的图片', {icon: 1, time: 3000});
                        return;
                    }
                });
            } else {
                uploadCount++;
            }
        }
    }*/

    layui.use(['form', 'layer', 'upload'], function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        // 回显地址二级
        if ($('#L_address').val() != null && $('#L_address').val() != '') {
            let parent, self = $('#L_address').val();
            for (var a in areas) {
                if (areas[a].id == parseInt(self)) {
                    parent = areas[a].pid;
                }
            }
            var select = 'dd[lay-value=' + parent + ']';
            $('#L_address_0').siblings("div.layui-form-select").find('dl').find(select).click();
            $('#L_address_1').html(new Option('请选择', '', true, false));
            for (var a in areas) {
                if (areas[a].pid == parseInt(parent)) {
                    $('#L_address_1').append(new Option(areas[a].name, areas[a].id, false, areas[a].id == parseInt(self) ? true : false));
                }
            }
            form.render();
        }

        //自定义验证规则
        form.verify({
            img: [/^\S+$/, '图片不能为空'],
            account: function (value) {
                    if (/^[a-zA-z]\w{3,15}$/.test(value)) {
                    return '账号为5-36个字以内'
                }
                var id = $('input[name="id"]').val();
                if (id == null || id == '') {
                    var msg = true;
                    $.ajax({
                        url: '/admin/user/get_by_account/' + value,
                        type: 'get',
                        async: false,
                        dataType: 'json',
                        success: function (result) {
                            msg = result;
                        }
                    })
                    if (!msg) {
                        return '该账号已存在';
                    }
                }
            },
            pwd: function (value) {
                if (value != null && value != '' && !/^(\w){6,20}$/.test(value)) {
                    return "密码为6-20个字符, 可包含字母、数字、下划线";
                }
            },
            nickname: [/(.+){2,36}$/, '昵称为2-36个字以内'],
            description: [/(.+){3,65}$/, '介绍为3到65个字'],
            address: [/^\S+$/, '地址不能为空'],
            graduateInstitution: [/(.+){3,200}$/, '毕业院校为3-200个字以内'],
            mainAchievements: [/(.+){3,200}$/, '主要成就为3-200个字以内'],
            personalizedSignature: [/(.+){3,150}$/, '一句话为3-150个字以内'],
            background: [/(.+){3,500}$/, '背景为3-500个字以内'],
        });

        // 地址选择
        form.on('select(address-selector-parent)', function (data) {
            $('#L_address').val('');
            $('#L_address_1').html(new Option('请选择', '', true, false));
            for (var a in areas) {
                if (areas[a].pid == parseInt(data.value)) {
                    $('#L_address_1').append(new Option(areas[a].name, areas[a].id, false, false));
                }
            }
            form.render();
        })
        form.on('select(address-selector-second)', function (data) {
            $('#L_address').val(data.value);
        })

        //监听提交
        form.on('submit(add)', function (data) {
            submitBusy(true);
            formData = data;
            interval = setInterval(updateUser, 300);
            uploadPortrat();
            // uploadPhoto();
            // uploadMobilePhoto();
            return false;
        });
    });
</script>

</body>
</html>